home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Information / FB Tech Notes Vol 2 < prev    next >
Text File  |  1993-07-14  |  14KB  |  369 lines

  1. ==================================================
  2.  
  3. Technical Note #10
  4. ____________________________________________
  5. Insensitive Include Files
  6. WRITTEN: 8 DEC 92 (LFT)
  7. LAST UPDATE: 8 DEC 92
  8. ____________________________________________
  9.  
  10. When using the COMPILE statement in a program with the _caseInsensitive parameter, you must ensure that any INCLUDE files called by the main program have an identical statement. Ignoring this can cause all kinds of problems.
  11.  
  12. When _caseInsensitive is used, FutureBASIC compares all variables AND function names in uppercase letters, if the INCLUDE file does not have this parameter set, the compiler can't match FN THIS (main program) with FN This (INCLUDE file).
  13.  
  14. Most simply, if you use a COMPILE settings in the main program, use the same one in all INCLUDE files used by the program.
  15.  
  16.  
  17. (Thanks to Roger Smith for finding this.)
  18.  
  19.  
  20.  
  21. ==================================================
  22.  
  23. Technical Note #11
  24. ____________________________________________
  25. Help File Blues
  26. WRITTEN: 31 DEC 92 (LFT)
  27. LAST UPDATE: 31 DEC 92
  28. ____________________________________________
  29.  
  30. When a user selects Help from the Apple menu its possible they will get an alert that displays a "Help file still under construction" message. This is somewhat misleading since the default help file is probably available but the Help tool isn't.
  31.  
  32. The problem is that the Help tool has inadvertantly been "turned off" or not enabled to autostart when FutureBASIC is opened. To re-enable the Help tool, use the Tool Manager under the Tools menu to view the current set of tools. Select the Help tool, then enable the Autostart button. This places a black diamond in front of the Help tool showing you it autostart is set for that tool.
  33.  
  34. When you close the Tool Manager, all tools set to autostart are re-initialized into memory.
  35.  
  36.  
  37. ==================================================
  38.  
  39. Technical Note #12
  40. ____________________________________________
  41. MUNGER Toolbox Correction
  42. WRITTEN: 6 JAN 93 (LFT)
  43. LAST UPDATE: 21 APR 93
  44. ____________________________________________
  45.  
  46. (Definition corrected in FB v1.02)
  47.  
  48. A definition error was discovered in the Toolbox with FN MUNGER. As it stood, the function failed to replace text in the handle even when it found it.
  49.  
  50. Fixing this Bug:
  51. You can use ResEdit to correct this problem by modifying a word in a resource in the Future Extras file.  The steps include:
  52.  
  53. 1.  Run ResEdit.
  54. 2.  Open Future Extras.
  55. 3.  Open the TlBx resource picker (shows all TlBx resources) 
  56. 4.  Open TlBx #129.
  57. 5.  Find offset &H496
  58. 6.  Replace &H05010501 with &H01010101
  59. 7.  Save your changes.
  60. 8.  Close FutureBASIC and quit ResEdit.
  61.  
  62.  
  63. (Thanks to Gary Thompson for finding this one.)
  64.  
  65.  
  66.  
  67. ==================================================
  68.  
  69. Technical Note #13
  70. ____________________________________________
  71. OSEvt Equates Correction
  72. WRITTEN: 7 JAN 93 (LFT)
  73. LAST UPDATE: 21 APR 93
  74. ____________________________________________
  75.  
  76. (Constants corrected in FB v1.02)
  77.  
  78. Two value errors were discovered in the OSEvt equates, Currently the settings are:
  79.  
  80. resumeFlag            = 0
  81. convertClipboardFlag  = 1
  82.  
  83. while they should be (ref. IM v6, p.5-33):
  84.  
  85. resumeFlag            = 1
  86. convertClipboardFlag  = 2
  87.  
  88. Fixing this Bug:
  89. You can use ResEdit to correct this problem by modifying a word in a resource in the Future Extras file.  The steps include:
  90.  
  91. 1.  Run ResEdit.
  92. 2.  Open Future Extras.
  93. 3.  Open the _Con resource picker (shows all _Con resources) 
  94. 4.  Open _Con #128.
  95. 5.  Find offset &HEF8
  96. 6.  Replace &H0000 with &H0001
  97. 7.  Find offset &HEFC
  98. 8.  Replace &H0001 with &H0002
  99. 9.  Save your changes.
  100. 10.  Close FutureBASIC and quit ResEdit.
  101.  
  102.  
  103. (Thanks to Rich Love for pointing to this one.)
  104.  
  105.  
  106. ==================================================
  107.  
  108. Technical Note #14
  109. ____________________________________________
  110. The Lost Text Dance
  111. WRITTEN: 13 JAN 93 (LFT)
  112. LAST UPDATE: 13 JAN 93
  113. ____________________________________________
  114.  
  115. The introduction of LOCAL FN was heralded as a boon to programmers being overrun with out-of-control global variables. This jubilation was justified, but, incorrect usage of LOCAL FNs can lead to a shortage of stack space in the program. This in turn can cause text in dialogs, menus, windows to not display, as well as system errors. Not something we are looking for in a well-behaved program.
  116.  
  117. A LOCAL FN takes the parameters passed to it and places them on the stack. Any variables dimensioned inside the LOCAL FN are also created on the stack. The stack space allocated to a particular machine varies but in many instances will be around 8K-32K.  If the size of the remaining stack is less than the LOCAL FN requires, a stack overflow can result, munging other code in memory
  118.  
  119. The following example demonstrates the problem:
  120.  
  121. LOCAL FN TestStack
  122.   DIM 255 test$ (49)
  123.   ' do something with these strings
  124. END FN
  125.  
  126. If we imagine we had a normal 8K stack, this simple DIM statement overflows the stack immediately (256 bytes * 50 strings = 12800 bytes, or about 4K more than the stack can handle. The first symptoms of stack shortages will be evident when text that once appeared just fine now fails to appear in file dialogs, windows, and in extreme cases, menus. Let's state one truism now:
  127.  
  128.      YOU CAN NOT USE LOCAL FNs LIKE YOU WOULD GOTO!
  129.  
  130. In other words, you cannot call FN after FN regardless of where they appear in the program just as you once did with GOTO. GOTO allows a one way jump to any point in a program. Unlike GOTO, each call to a LOCAL FN places a return address on the stack causing it to grow. With enough FN calls that DON'T RETURN to the originating point, its possible to execeed the original 8k of stack space very rapidly.
  131.  
  132. Instead, a LOCAL FN must be considered like a GOSUB statement. A GOSUB jumps to any point in a program, BUT, it places a return address on the stack that allows program control to jump back to its previous position when a RETURN is encountered.
  133.  
  134. The best example of performing calls to LOCAL FNs correctly are shown in the example programs included on the Examples disk.
  135.  
  136. You can determine the amount of stack space available and reset it using the following routine:
  137.  
  138. "IncreaseStackSpace"
  139. LONG IF [_applLimit] - [_heapEnd] < maxHeapSize&
  140.   & [_applLimit], [_heapEnd] + maxHeapSize&
  141. END IF
  142.  
  143. This routine should only be called ONCE in the program before executing any other initialization routines.
  144.  
  145.  
  146. (Thanks to host of people for finding this one.)
  147.  
  148.  
  149. ==================================================
  150.  
  151. Technical Note #15
  152. ____________________________________________
  153. GETPIXELSSTATE Toolbox Correction
  154. WRITTEN: 19 JAN 93 (LFT)
  155. LAST UPDATE: 21 APR 93
  156. ____________________________________________
  157.  
  158. (Toolbox corrected in FB v1.02)
  159.  
  160. A definition error was discovered in the Toolbox with FN GETPIXELSSTATE. As defined, the function returned a word value when a longInt is expected.
  161.  
  162. Fixing this Bug:
  163. You can use ResEdit to correct this problem by modifying a word in a resource in the Future Extras file.  The steps include:
  164.  
  165. 1.  Run ResEdit.
  166. 2.  Open Future Extras.
  167. 3.  Open the TlBx resource picker (shows all TlBx resources) 
  168. 4.  Open TlBx #129.
  169. 5.  Find offset &H7C6
  170. 6.  Replace &H02F00004 with &H03F00004
  171. 7.  Save your changes.
  172. 8.  Close FutureBASIC and quit ResEdit.
  173.  
  174.  
  175.  
  176. ==================================================
  177.  
  178. Technical Note #16
  179. ____________________________________________
  180. Assembler Non-Features
  181. WRITTEN: 10 FEB 93 (JAR)
  182. LAST UPDATE: 5 APR 93
  183. ____________________________________________
  184.  
  185.  
  186. FutureBASIC's built-in assembler currently has a few limitations and, well, how shall we put it, "unexpected features"?  If you use the built-in assembler, you will probably want to be aware of the following problems:
  187.  
  188. 1)  Spaces must NOT be used between instruction operands.  For example, the following statement will assemble incorrectly:
  189.  
  190.    `  move.l      ^MyVar&, d0
  191.  
  192. but
  193.  
  194.    `  move.l      ^MyVar&,d0
  195.  
  196. will assemble correctly.
  197.  
  198.  
  199. 2) The assembler will not currently accept the condition code register as an operand.  Thus, the instruction
  200.  
  201.    `  move         CCR,-(sp)
  202.  
  203. will cause the compiler to complain.  Of course, you can always work around a problem like this by using the assembler's dc.w and dc.l directives.  For instance, the above instruction could be assembled as follows:
  204.  
  205.    _PushCCR =      &42E7
  206.    `  dc.w         PushCCR
  207.  
  208. or:
  209.  
  210.    _PushSR =       &40E7
  211.    `  dc.w         PushSR
  212.  
  213. 3) The assembler reverses the operands of an EOR instruction (although it makes no similar mistake with the Winnie the Pooh instruction).  For example, if you really want to exclusive-or the d2 data register with the d0 data register, be sure to write
  214.  
  215.    `  eor.l        d0,d2
  216.  
  217. rather than
  218.  
  219.    `  eor.l        d2,d0
  220.  
  221. as you would expect!
  222.  
  223.  
  224.  
  225. ==================================================
  226.  
  227. Technical Note #17
  228. ____________________________________________
  229. HandAndHand Flops
  230. WRITTEN: 23 FEB 93 (LFT)
  231. LAST UPDATE: 29 APR 93
  232. ____________________________________________
  233.  
  234. (Added in FB v1.02)
  235.  
  236. A definition error was discovered in the Toolbox with FN HANDANDHAND. As it stood, the function was missing a parameter and returned the incorrect result.
  237.  
  238. Fixing this Bug:
  239. You can use ResEdit to correct this problem by modifying a word in a resource in the Future Extras file.  The steps include:
  240.  
  241. 1.  Run ResEdit.
  242. 2.  Open Future Extras.
  243. 3.  Open the TlBx resource picker (shows all TlBx resources) 
  244. 4.  Open TlBx #129, "FN".
  245. 5.  Select Find Hex from the Find menu.
  246. 6.  Find Hex: 0506A9E40BFF and Change to: 0604A9E40B0CFF 
  247. 7.  Save your changes.
  248. 8.  Close FutureBASIC and quit ResEdit.
  249.  
  250.  
  251. (Thanks to Chris Dwyer for finding this one.)
  252.  
  253.  
  254. ==================================================
  255.  
  256. Technical Note #18
  257. ____________________________________________
  258. SETPTRSIZE Addition
  259. WRITTEN: 8 MAR 93 (LFT)
  260. LAST UPDATE: 21 APR 93
  261. ____________________________________________
  262.  
  263. (Added in FB v1.02)
  264.  
  265. The Toolbox procedure SETPTRSIZE mentioned in the Handbook (p.345) was discovered to not be available in FutureBASIC.
  266.  
  267. Adding the Trap:
  268. You can use ResEdit to add this procedure using the following steps:
  269.  
  270. 1.  Run ResEdit.
  271. 2.  Open a copy of FUTURE Extras.
  272. 3.  Open the TlBx resource picker (shows all TlBx resources)
  273. 4.  Open TlBx #129.
  274. 5.  Select Find Offset from the Find menu.
  275. 6.  Find Offset: 1DA
  276. 7.  Enter at the selection point (the 06A8): 0604A0200B0AFF 
  277. 8.  Close the TlBx resources.
  278. 9.  Open the STR# resource picker (shows all STR# resources) 
  279. 10.Open STR# #129.
  280. 11.Locate item #65 (SETHANDLESIZE).
  281. 12.Click on the ***** above the 65.
  282. 12.Choose Create New Resource from the Resource menu. 
  283. 13.Enter: SETPTRSIZE into the blank item (it should be between SETVOL and SETHANDLESIZE)
  284. 14. Close the STR# resource.
  285. 15.Save all of your changes.
  286. 16.Close FutureBASIC and quit ResEdit.
  287. 17.Switch the copy of FUTURE Extras with the original and test.
  288.  
  289.  
  290.  
  291. ==================================================
  292.  
  293. Technical Note #19
  294. ____________________________________________
  295. LOCAL FN Explained
  296. WRITTEN: 6 MAY 93 (LFT)
  297. LAST UPDATE: 6 MAY 93
  298. ____________________________________________
  299.  
  300. Included here is additional information on the habits of LOCAL FNs hitherto unknown and undocumented.
  301.  
  302. A LOCAL FN is a self-contained program within the confines of a regular program. This allows the programmer to isolate routines from each other and avoid variable corruption.
  303.  
  304. When a LOCAL FN receives a parameter it makes a copy of the variable being passed thus ensuring that the original is never changed.  When the routine exits via END FN or EXIT FN the local variable is removed from memory and no longer exists.
  305.  
  306.  
  307. Multi-variable updating
  308.  
  309. There are three methods for updating multiple variables passed to a LOCAL FN. They include: globals, addresses, and records.
  310.  
  311. The first is the easiest but not the cleanest method of updating several variables wihtin a LOCAL FN. Define all the variables that need updating as global. You can then access them directly and change their values easily.
  312.  
  313. The second method requires that the address of the variable be passed to the LOCAL FN. The LOCAL FN makes changes by PEEKing and POKEing at the address. If you understand PEEK and POKE than this method works great.
  314.  
  315. The final method requires that you define a temporary record structure to pass the variables into the LOCAL FN (a paramblock) and then pass the record address to the function. You than access and update the record variables directly using normal record input and output methods. (ie. myRecPtr&.varOne% = 10). This method works well for those who don't think in PEEK and POKE terms.
  316.  
  317.  
  318. Mysterious values
  319.  
  320. In certain circumstances you may find that a variable you thought you had defined locally in a LOCAL FN has mysteriously appeared in your main program.
  321.  
  322.  
  323. This problem is easy to reproduce by defining a simple LOCAL FN that accepts a variable BUT DOESN'T return one. When used with the PRINT statement the value of the local variable 'q' is printed. Here is the example:
  324.  
  325. LOCAL FN Fred (tmp%)
  326.   q = 45
  327. END FN
  328.  
  329. PRINT FN Fred (21)
  330.  
  331. Results in an output of:
  332.  
  333. 45
  334.  
  335. Which is incorrect. Or is it?
  336.  
  337. The reason this situation occurs is simple. FB always uses Register D0 to return variables from any FN. The last variable assigned in the FN will always be found in D0. The END FN statement doesn't clear D0 when it executes thus leaving D0 holding the last variable bag. The PRINT statement simply prints what it finds in Register D0, the mysterious local variable left there by FN Fred.
  338.  
  339. If the END FN had contained a variable assignment, no anomoly would have occurred.
  340.  
  341. LOCAL FN Fred (tmp%)
  342.   q = 45
  343. END FN = tmp%
  344.  
  345. PRINT FN Fred (21)
  346.                     LOCAL FN Fred (tmp%)
  347.  
  348. Results in an output of:
  349.  
  350. 21
  351.  
  352. exactly as expected.
  353.  
  354.  
  355. ==================================================
  356.  
  357. Technical Note #20
  358. ____________________________________________
  359. ON EVENT GOTO Error
  360. WRITTEN: 6 MAY 93 (LFT)
  361. LAST UPDATE: 6 MAY 93
  362. ____________________________________________
  363.  
  364. The statement ON EVENT GOTO documented in the Reference manaul p. 261 is not a legal statement.
  365.  
  366. You must use ON <event> FN or ON <event> GOSUB instead.
  367.  
  368.  
  369.